﻿using System;
using Terraria.ID;
using Terraria.ModLoader.Exceptions;

namespace Terraria.ModLoader
{
	// Token: 0x02000202 RID: 514
	internal static class RecipeGroupHelper
	{
		// Token: 0x060016CA RID: 5834 RVA: 0x00011645 File Offset: 0x0000F845
		internal static void ResetRecipeGroups()
		{
			RecipeGroup.recipeGroups.Clear();
			RecipeGroup.recipeGroupIDs.Clear();
			RecipeGroup.nextRecipeGroupIndex = 0;
		}

		// Token: 0x060016CB RID: 5835 RVA: 0x00416728 File Offset: 0x00414928
		internal static void AddOldVanillaGroups()
		{
			RecipeGroup rec = new RecipeGroup(() => Lang.misc[37].Value + " " + Lang.GetItemNameValue(9), new int[]
			{
				9,
				619,
				620,
				621,
				911,
				1729,
				2503,
				2504
			});
			RecipeGroupID.Wood = RecipeGroup.RegisterGroup("Wood", rec);
			rec = new RecipeGroup(() => Lang.misc[37].Value + " " + Lang.GetItemNameValue(22), new int[]
			{
				22,
				704
			});
			RecipeGroupID.IronBar = RecipeGroup.RegisterGroup("IronBar", rec);
			rec = new RecipeGroup(() => Lang.misc[37].Value + " " + Lang.misc[38].Value, new int[]
			{
				529,
				541,
				542,
				543,
				852,
				853,
				1151
			});
			RecipeGroupID.PressurePlate = RecipeGroup.RegisterGroup("PresurePlate", rec);
			rec = new RecipeGroup(() => Lang.misc[37].Value + " " + Lang.GetItemNameValue(169), new int[]
			{
				169,
				408,
				1246,
				370,
				3272
			});
			RecipeGroupID.Sand = RecipeGroup.RegisterGroup("Sand", rec);
			rec = new RecipeGroup(() => Lang.misc[37].Value + " " + Lang.misc[51].Value, new int[]
			{
				3458,
				3456,
				3457,
				3459
			});
			RecipeGroupID.Fragment = RecipeGroup.RegisterGroup("Fragment", rec);
		}

		// Token: 0x060016CC RID: 5836 RVA: 0x00416898 File Offset: 0x00414A98
		internal static void AddRecipeGroups()
		{
			foreach (Mod mod in ModLoader.mods.Values)
			{
				try
				{
					mod.AddRecipeGroups();
				}
				catch (Exception inner)
				{
					ModLoader.DisableMod(mod.Name);
					throw new AddRecipesException(mod, "An error occured in adding recipe groups for " + mod.Name, inner);
				}
			}
			RecipeGroupHelper.FixRecipeGroupLookups();
		}

		// Token: 0x060016CD RID: 5837 RVA: 0x00416920 File Offset: 0x00414B20
		internal static void FixRecipeGroupLookups()
		{
			for (int i = 0; i < RecipeGroup.nextRecipeGroupIndex; i++)
			{
				RecipeGroup recipeGroup = RecipeGroup.recipeGroups[i];
				recipeGroup.ValidItemsLookup = new bool[ItemLoader.ItemCount];
				foreach (int num in recipeGroup.ValidItems)
				{
					recipeGroup.ValidItemsLookup[num] = true;
				}
			}
		}
	}
}
